import socket from './index'
import { ElNotification } from 'element-plus'
import { useUserInfoStore } from "@/store/modules/user"
import { useContactStore } from "@/store/modules/contact"
const userInfoStore = useUserInfoStore()
const contactStore = useContactStore()

socket.on('login', () => {
    ElNotification({
        title: userInfoStore.userInfo.nick + '已上线',
        type: 'success'
    })
})

// 联系人页面申请消息数量的ts类型
type ContactNum = {
    friendNoticeNum: number;
    groupNoticeNum: number;
}
// 获取好友/群消息数量
socket.on('notice_num', (val: ContactNum) => {
    contactStore.SOCKET_ContactNum(val.friendNoticeNum, val.groupNoticeNum)
})

// 发送好友/群申请，接受放获取消息数量
socket.on('apply_notice', (val: ContactNum) => {
    contactStore.SOCKET_ContactNum(val.friendNoticeNum, val.groupNoticeNum)
})